﻿using Ctyun.CF.SDK.Core;
using System.Text.Json;

namespace Ctyun.CF.SDK.Example;

internal class InvokeWorkflowExample
{
    static void Main(string[] args)
    {
        string functionName = "Your-functionName";

        CTApiClient client = new CTApiClient.Builder()
            .Endpoint("https://cf.fc-xinan1.ctyun.cn") // 云工作流 API invoke endpoint，必填
            .Region("200000002368") // Region，必填，示例为：西南1
            .Ak("Your-AK")  // 天翼云AK，必填
            .Sk("Your-SK")  // 天翼云SK，必填
            .Build();

        var options = new JsonSerializerOptions
        {
            PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
            DictionaryKeyPolicy = JsonNamingPolicy.CamelCase
        };

        var request = new InvokeFlowRequest
        {
                WorkflowName = "newv",
                Input = "{\"a\":1}",
                ExecutionName = "testExecution"
        };

        // 序列化请求对象
        var requestBody = JsonSerializer.Serialize(request, options);

        var jsonString = client.Request("POST", "/openapi/v1/execution/start", null, requestBody);

        Console.WriteLine($"Invoke result: {jsonString}");
    }
}
